<template>
    <div>
        <group>
            <cell title="提现渠道" @click.native="encash_channel" is-link></cell>
            <x-input title="账户" v-model="cash.account" placeholder="输入提现账户"></x-input>
            <x-input title="姓名" v-model="cash.name" placeholder="账户的姓名 真实姓名"></x-input>
            <template v-if="cash.channel_type === 'bank'">
                <x-input title="开户行" v-model="cash.channel_title" placeholder="开户银行,如[建设银行]"></x-input>
                <x-input title="支行" v-model="cash.open_bank" placeholder="支行名称, 如[上海南京东路支行]"></x-input>
            </template> 
        </group>
        <group>
            <x-button @click.native="setDepoist" type="primary">确认</x-button>       
        </group>
        <actionsheet v-model="sheet" :menus="menu" @on-click-menu="click_cash"></actionsheet>
    </div>
</template>
<script>
    import {XButton, XInput, Cell, Group, Actionsheet} from 'vux'
export default {
    components: {
        XButton,
            XInput,
            Cell,
            Group,
            Actionsheet
    },
    data() {
        return {
            cash: {
                name: null,
                    account: null,
                    channel_type: null,
                    open_bank: null,
                    channel_title: null
            },
            sheet: false,
            menu: {
                bank: "银行卡"
            },
        }    
    },
    created(){
        this.$store.commit("storeState", false)

    },
    methods: {
        setDepoist(){
            this.$http.post("users/cash_account.json", this.cash).then(res => {
                console.log(this.cash)
                let data = res.data
                if (data.code === 200) {
                    this.$router.push({path: "msg"})
                } else {
                    this.$vux.alert.show({
                        title: "提交失败",
                        content: data.msg
                    })
                }
            })
        },
            encash_channel(){
                this.sheet = true
            },
            click_cash(key) {
                this.cash.channel_type = key
            },

    }

}
</script>
